package com.lyz.dataStructure.LeetCode.ListNode;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 20:09
 * @Description:
 **/

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/7/19 20:09
 *@Description:
 **/
public class ReverseListNode {
    public static void main(String[] args) {
        ListNode node = createListNode();
        System.out.println(node);

        System.out.println(reverseListNode(node));
    }

    public static  ListNode createListNode(){
        ListNode listNode = new ListNode(0);
        ListNode curr = listNode;
        for(int i=1;i<5;i++){
            curr.next = new ListNode(i);
            curr = curr.next;
        }
        return listNode;
    }

    public static ListNode reverseListNode(ListNode head){
        if(head==null) return null;
        ListNode prev  = null;
        ListNode curr = head;
        while (curr!=null){
            ListNode nextNode = curr.next;
            curr.next =prev;
            prev = curr;
            curr =nextNode;
        }
        return prev;
    }
}
